package top.kaoshanji.t1ch10c.controllers.advice;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.kaoshanji.t1ch10c.exceptions.NotEnoughMoneyException;
import top.kaoshanji.t1ch10c.model.ErrorDetails;

/**
 * 代码清单-t1ch10c-218页b：用REST控制器通知分离异常逻辑
 * @author kaoshanji
 * ^_^
 * create time 2025/4/30 19:35
 */
@RestControllerAdvice
public class ExceptionControllerAdvice {

    @ExceptionHandler(NotEnoughMoneyException.class)
    public ResponseEntity<ErrorDetails> exceptionNotEnoughMoneyHandler() {
        ErrorDetails errorDetails = new ErrorDetails();
        errorDetails.setMessage("....Not enough money...");

        return ResponseEntity.badRequest().body(errorDetails);
    }

}
